<?php
GLOBAL $CFG;
require_once('../../../config.php');

require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/local/blackboxsurvey/forms.php");

//yeu cau login,sau khi login tu dong chuyen sang trang chu
global $USER;
if ($USER->id == null){
    $SESSION->homepage = true;
    require_login($SITE);
}
if($SESSION->homepage){
    $SESSION->homepage = null;
    redirect( $CFG->wwwroot);
}

//class
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questionaire.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/matching.php");
$path = $CFG->wwwroot.'/local/blackboxsurvey/matcher/manage_bbsurvey.php';
$path_image = $CFG->wwwroot .'/local/blackboxsurvey/image/';

$id_bbsurvey = required_param('id_bbsurvey', PARAM_TEXT);
$id_subject = required_param('id_subject', PARAM_TEXT);
$array['path_image'] = $path_image;
//Them thanh menu ngang ung voi trang trong duong link
//navigation_node::override_active_url(new moodle_url($path, array('param'=>'value')));

/* Chuan bi trang web can hien thi */	
//$url = new moodle_url($path);
//$PAGE->set_url($url);
//$PAGE->set_title('Matching Survey Management');
//$PAGE->set_heading('Matching Survey Management');
//$PAGE->set_pagelayout('standard');
//echo $OUTPUT->header();

$c_qn = new b_questionaire();
$c_mat = new b_matching();
//lay thong tin co ban mon matching
$survey = $c_qn->get_questionaire_info($id_bbsurvey,$id_subject);
$array['program'] = $survey->program_name;
$array['subject'] = $survey->subject_name_vn;
$array['start'] = $survey->date_start;
$array['end'] = $survey->date_end;

//lay danh sacc prerequisite subject
$prerequisites = $c_mat->show_prerequisite_subject_bySubject($id_bbsurvey, $id_subject);
$array['prerequisite_subject'] = $prerequisites['prerequisite_subject'];
//lay chi tiet input
$array['input_detail'] = $c_mat->show_matched_input_bySubject($id_bbsurvey, $id_subject, $prerequisites['prerequisite_list']);
//lay danh sach receive subject
$receive = $c_mat->show_receive_subject_bySubject($id_bbsurvey, $id_subject);
$array['receive_subject'] = $receive['receive_subject'];
//lay chi tiet output
$array['output_detail'] = $c_mat->show_matched_output_bySubject($id_bbsurvey, $id_subject, $receive['receive_list']);

//truyen data len giao dien
$mform = new form_view_matching_result(null, $array);
$mform->display();
echo $id_subject;
/*------Ket thuc doan code cua ban-------*/
//echo $OUTPUT->footer();
